import type { IColumnsOption } from 'vc';
import { INDEX, COMPANY_NAME, INFO_SOURCE, PROVINCE, CITY, COUNTRY, INDUSTRY_CATEGORY, BUSINESS_DATA, REGISTERED_CAPITAL, CellRenderMap } from '@/utils';

export function useTable() {
  const columns = ref<IColumnsOption[]>([
    { ...INDEX },
    { ...COMPANY_NAME },
    {
      title: '披露日期',
      field: 'noticeDate',
      width: 100,
      align: 'center',
      sortable: true
    },
    {
      ...INFO_SOURCE('dataSource'),
      width: 200
    },
    {
      title: '许可证编号',
      field: 'certificateNumber',
      width: 150,
      align: 'center',
      sortable: true,
      cellRender:{ name: CellRenderMap.HighLight }
    },
    {
      title: '变动类别',
      field: 'changeTypeCode',
      width: 150,
      align: 'center',
      sortable: true
    },
    {
      title: '许可阶段',
      field: 'approvalStageCode',
      width: 150,
      align: 'center',
      sortable: true
    },
    {
      title: '发证机关',
      field: 'issuingDepartment',
      width: 200,
      align: 'center',
      sortable: true
    },
    {
      title: '发证日期',
      field: 'periodOfValidityStartDate1',
      width: 100,
      align: 'center',
      sortable: true,
      formatter({ row }) {
        return row.periodOfValidityStartDate || '-';
      }
    },
    {
      title: '有效起止日期',
      width: 250,
      field: 'periodOfValidityStartDate2',
      align: 'center',
      sortable: true,
      slots: {
        default({ row }) {
          const showText = row.isExpired !== null ? (row.isExpired ? '过期' : '有效') : '';
          const className = 'revocation ' + 'revocation-' + row.isExpired;
          const isEmpty = row.periodOfValidityStartDate || row.periodOfValidityExpirationDate;

          return (
            <span>
              {isEmpty ?
                <span>{row.periodOfValidityStartDate || '-'} 至 {row.periodOfValidityExpirationDate || '-'}</span>
                : '-'}
              {showText ? <span title={showText} class={className}>
                {showText}
              </span> : ''}
            </span>
          );
        }
      }
    },
    {
      title: '种类和范围',
      field: 'rayDeviceTypes',
      width: 220,
      showOverflow:'title'
    },
    { ...PROVINCE },
    { ...CITY },
    { ...COUNTRY },
    { ...INDUSTRY_CATEGORY },
    { ...BUSINESS_DATA },
    { ...REGISTERED_CAPITAL }
  ]);

  return {
    columns
  };
}
